from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.

class User(AbstractUser):
    """用户模型类"""

    #定义手机号字段
    mobile = models.CharField(max_length=11, verbose_name='手机号', unique=True)

    # 对当前表进行相关设置:
    class Meta:
        db_table = 'tb_users'
        verbose_name = '用户'
        verbose_name_plural = verbose_name

    # 在 str 魔法方法中, 返回用户名称
    def __str__(self):
        return self.username

######################################################################
class Production(models.Model):
    """商品分类"""
    name = models.CharField(max_length=20, verbose_name='名称')
    parent = models.ForeignKey('self', on_delete=models.CASCADE, related_name='subs', null=True, blank=True, verbose_name='父分类')
    price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='价格')
    description = models.TextField(verbose_name='商品描述')
    guojia = models.CharField(max_length=20, verbose_name='国家')

    class Meta:
        db_table = 'tb_Production'
        verbose_name = '商品表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name